package cn.ichenkun.web.servlet;

import cn.ichenkun.util.JDBCUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/StoreGroupServlet")
public class StoreGroupServlet extends HttpServlet {

    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");

        String sql = "insert into `group` (`name`) value (?)";
        //2.执行sql
        template.update(sql, request.getParameter("name").toString());

        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        request.setAttribute("users",users);
//        //3.转发到list.jsp
//        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
